#!/bin/bash
BASH_PATH=$(cd `dirname $0`; pwd)
SEVER_URL='http://192.168.10.102:4023/webapi/entry.cgi?api=SYNO.Chat.External&method=chatbot&version=2&token=%220QdrEwmNkN3P13pDzS76yEv95qkC9zqG9WoXqSj9hcx4fTrtmr7Uie8TxOseRmP5%22'
TITLE=$1
MESSAGE=$2
MESSAGE2=$3
LOG_FILE=${BASH_PATH}/log/chat_robot.log

function LOG() {
    USER=$(whoami) ####那个用户在操作
    if [ ! -f ${LOG_FILE} ];then
       touch ${LOG_FILE}
    fi
    echo "[${DATE}] ${USER} [$1] $2"
    echo "[${DATE}] ${USER} [$1] $2" >> ${LOG_FILE} 
}

function main()
{
    mkdir -p ${CURRENT_PATH}/log
    curl --location --request POST 'http://192.168.10.102:4023/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22IDZnXuzEf27bQrOXhNefQBgyGeh8ZEcjz8v3AaoVH4NSuCttqtfYdp0BWW5vQP95%22' \
    --header 'Content-Type: text/plain' \
    --data 'payload={"text": "'[$1]'\n'"$2"'\n'"$3"'\n''"}'
    RET=$?
    LOG INFO "status: $RET, text: [$1] $2 $3\n"
}

main $TITLE $MESSAGE $MESSAGE2

# 事例
# curl --location --request POST 'http://192.168.10.96:5000/webapi/entry.cgi?api=SYNO.Chat.External&method=chatbot&version=2&token=%22LspD521Gu9GEK0CN2Y4ZkO0hVTrUMLNorJ3ogVEQV0WxOJB8iuHx6jQbRcvKBfRD%22' \
# --header 'Content-Type: text/plain' \
# --data-raw 'payload={"text": "This is a test","user_ids": [4]  }'